package org.example.mall.Mapper;

import org.apache.ibatis.annotations.*;
import org.example.mall.Pojo.ConsigneeInfo;
import org.example.mall.Pojo.Order;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface OrderMapper {
    //订单查询
    @Select("select * from ProductOrder where userName = #{userName}")
    List<Order> getUserOrderListByUserName(String userName);
    @Select("select * from ProductOrder where oId = #{oId}")
    Order getUserOrderByOId(Integer oId);
    //创建与删除
//    @Insert("insert into ProductOrder(userName, pId, price, cId, status, createDate) values (#{arg0}, #{arg1}, #{arg2}, #{arg3}, 0, now())")
//    void createOrder(String userName, String pId, Float price, Integer cId);
    @Insert("insert into ProductOrder(userName, pId, price, cId, status, createDate) values (#{userName}, #{pId}, #{price}, #{cId}, 0, now())")
    @Options(useGeneratedKeys=true, keyProperty="oId", keyColumn="oId")
    void createOrder(Order order);
    @Delete("delete from ProductOrder where oId = #{oId}")
    void deleteOrderByOId(Integer oId);
    //订单修改
    @Update("update ProductOrder set completeDate = now() where oId = #{oId}")
    void updateOrderCompleteDate(Integer oId);
    @Update("update ProductOrder set status = #{arg1} where oId = #{arg0}")
    void updateOrderStatus(Integer oId, Integer status);
    @Update("update ProductOrder set cId = #{arg1} where oId = #{arg0}")
    void updateOrderConsignee(Integer oId, Integer cId);

    @Select("select count(*) from ProductOrder where cId = #{arg0}")
    Integer countOrderByCId(Integer cId);

}
